import React, { useState } from 'react';
import { getLocalUserInfo } from 'utils/util'

export const HomeContext = React.createContext({});

export default (props) => {
    const [user, setUser] = useState(getLocalUserInfo()); // 用户信息
    const [type, setType] = useState('add'); // 编辑类型 [add,edit,delete]
    const [visible, setVisible] = useState(false); // 新增|编辑弹窗
    const [viewPassVisible, setViewPassVisible] = useState(false); // 查看密码
    const [viewMoreVisible, setViewMoreVisible] = useState(false); // 查看更多
    const [record, setRecord] = useState(null);

    // 新增或者编辑时[显示弹窗,设置操作类型,设置表单数据]
    const editHandle = (visible, type, data) => {
        setVisible(visible)
        setType(type)
        setRecord(data)
    }
    // 查看密码弹窗[显示弹窗,设置数据]
    const viewPassHandle = (visible, data) => {
        setViewPassVisible(visible)
        setRecord(data)
    }
    // 查看详情弹窗[显示弹窗设置数据]
    const viewMoreHandle = (visible, data) => {
        setViewMoreVisible(visible)
        setRecord(data)
    }

    const value = {
        user, setUser,
        visible, setVisible,
        viewPassVisible, setViewPassVisible,
        viewMoreVisible, setViewMoreVisible,
        type, setType,
        record, setRecord,
        
        editHandle,
        viewPassHandle,
        viewMoreHandle,
    }
    return value;
    // return (
    //     <HomeContext.Provider value={value}>
    //         {props.children}
    //     </HomeContext.Provider>
    // )
}